package com.attendance.service.impl;

import com.attendance.mapper.TypeMapper;
import com.attendance.model.Type;
import com.attendance.service.ITypeService;
import com.baomidou.framework.service.impl.SuperServiceImpl;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Type 表数据服务层接口实现类
 */
@Service
public class TypeServiceImpl extends SuperServiceImpl<TypeMapper, Type> implements ITypeService {

    @Autowired
    private TypeMapper typeMapper;

    public Type getById(Integer id) {
        return typeMapper.getById(id);
    }

    public List<Type> getAll(Type type) {
        EntityWrapper<Type> ew = new EntityWrapper<Type>();
        ew.where("1=1");
        if (type.getId() != null) {
            ew.andNew("id={0}", type.getId());
        }
        if (type.getName() != null) {
            ew.like("name", type.getName());
        }
        if (type.getMemo() != null) {
            ew.like("memo", type.getMemo());
        }
        if (type.getDiscount() != null) {
            ew.andNew("discount={0}", type.getDiscount());
        }
        return this.baseMapper.selectList(ew);
    }
}